package com.baizhi.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class DdController {

   @Autowired
   private RestTemplate restTemplate;//跨服务调用
    @Value("${server.port}")
    private int port;

    @GetMapping("dds/{id}")
    @HystrixCommand(fallbackMethod = "abc")
    public String selectDd(@PathVariable("id") Integer id){
        String url="http://sp-zz/sp/sps/2";
        //调用订单查询的时候去查一下商品服务。
        String result = restTemplate.getForObject(url, String.class);
        System.out.println(result);

        System.out.println("result = " + result);
        System.out.println("ssssssssssssssssssssssssssssssssss");
        return "我是订单服务窗口 端口是"+port+",我的参数是"+id+"===="+result;
    }
    public String abc(Integer id){
        return  "熔断器打开,参数为:"+id;
    }
}
